﻿using FarseerGames.FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FarseerGames.FarseerPhysics;

namespace XNA_2DFramwork
{
    public class Rectangel : VisualObject
    {
        private Vector2 _origin;
      
        public Color Color;

        public Rectangel(Game game ,int width, int height, Vector2 position,Color color, GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator):base(game)
        {
            Width = width;
            Height = height;
           
            Position = position;
            Color = color;

            Texture = DemoBaseXNA.DrawingSystem.DrawingHelper.CreateRectangleTexture(graphicsDevice, Width, Height, Color.White, Color.Black);
            _origin = new Vector2(Texture.Width / 2f, Texture.Height / 2f);
            Width = Texture.Width;
            Height = Texture.Height;
            Body = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, Width, Height, 1);
            Body.Position = Position;
            Geom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, Body, Width, Height);
           
            
            SpriteBatch = new SpriteBatch(graphicsDevice);
        }


        public override void Draw()
        {
            SpriteBatch.Begin();
            SpriteBatch.Draw(Texture, Body.Position, null, Color, Body.Rotation, _origin, 1f, SpriteEffects.None, 0f);
            SpriteBatch.End();
        }

        public override void Update()
        {

        }

       
    }
}
